PocketPyro For Palm Development by Linden DeCarmo Listing One Err err; FileHandle handle; MediaFileDesc *mediaDesc; mediaDesc.size = sizeof(MediaFileDesc); handle = MediaFileOpen(libRef, DEVICE_ID_POCKET_PYRO, pCallback, // PFN_DEVFILE_EVENTS callback &mediaDesc, // media description 0, fileModeReadOnly, &err); // interesting info is returned in the MediaFileDesc // for instance mediaDesc.pFileName has the filename Listing Two // open a file handle = MediaFileOpen(libRef, DEVICE_ID_POCKET_PYRO, pCallback, // PFN_DEVFILE_EVENTS callback &mediaDesc, 0, fileModeReadOnly, &err); // start playing it MediaFilePlay(libRef, hcontext, handle); Listing Three Int count; Err rc; // get the number of devices in for the default device. rc = MediaControlGetCount(libRef, -1, // default device AUDIO_OUTPUT_CONTROL, &count); if ( !rc ) { // if rc == 0, then count contains the number of controls... } Listing Four Err rc; int value; int id; // get the control id, we'll use it to get/set attributes rc = MediaControlGetId(libRef, DEVICE_ID_POCKET_PYRO, AUDIO_OUTPUT_CONTROL, // control type 0, &id); // retrieve the current volume setting for the control... rc = MediaControlGetAttr(libRef, id, // control id AUDIO_CONTROL_VOLUME, &value); // modify the setting.... value++; // change the current volume setting... rc = MediaControlSetAttr(libRef, id, // control id AUDIO_CONTROL_VOLUME, &value); Listing Five // this handler is called when the state of the MediaContext changes // pEvent->eType contains the type of event to monitor Err MediaEventCallback(MediaContext hcontext, MediaEvent *pEvent) { // pEvent->eType is the type of event that occurred // the switch illustrates the type of events you can check for..... switch(pEvent->eType) { case mediaPlayStartEvent: break; case mediaPlayStopEvent: break; case mediaPosEvent: break; case mediaPausedEvent: break; case mediaResumedEvent: break; } return ( 0 ); } Listing Six MediaContext hContext; Err err; // create a logical context...its empty be default. hContext = MediaContextContext(libRef, pMediaEventCallback, &err); if ( !err ) { // indicate that we want audio output control... err = MediaContextAddComponent (libRef, hcontext, -1, AUDIO_OUTPUT_CONTROL, 0); // component # } Listing Seven MediaContext hContext; Err err; FileHandle handle; handle = MediaFileOpen(libRef, DEVICE_ID_POCKET_PYRO, pCallback, // PFN_DEVFILE_EVENTS callback &mediaDesc, 0, fileModeReadOnly, &err); hContext = MediaContextContext(LibRef libRef, pMediaEventCallback, &err); if ( !err ) { err = MediaContextAddComponent (libRef, hcontext, -1, AUDIO_OUTPUT_CONTROL, 0); if ( !err ) { // start playback to our media context.... err = MediaPlay(LibRef libRef, hContext, handle); } } Listing Eight // this handler is called when the state of MediaContext changes pEvent->eType // contains the type of event to monitor in this case, we're looking for // MediaBufferRequestEvent so we can feed FireStream additional buffers Err MediaEventCallback(MediaContext hcontext, MediaEvent *pEvent) { Err err; UInt8 buffer[4096]; switch(pEvent->eType) { case MediaBufferRequestEvent: { MediaFormat format; format.size = sizeof(MediaFormat); format.eType = mediaFormatAudio; format.data.audioFormat.codec = audioMP3 format.data.audioFormat.bitRate = 88200; format.data.audioFormat.bitsPerSample = 16; format.data.audioFormat.samplesPerSecond = 44100; format.data.audioFormat.channels = 2; // play another buffer and have an event generated when // firestream is done with it.. err = MediaPlayBuffer(LibRef libRef, // ??? value ???? hContext, &buffer, 4096, &format, MEDIA_GENERATE_BUFFER_REQUEST ); } break; } return ( 0 ); } 1